package keshe.dayin;



import keshe.DataBaseCreate;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class studentDao {

    private static Connection conn = null;

    private static PreparedStatement pst = null;

    private static ResultSet rs = null;

    public List<student> getstudentList() {
        List<student> list = new ArrayList<>();
        try {
            conn = DataBaseCreate.getConnection();
            String sql = "select Num,Name,Major,Maths,Chinese,English from student";
            pst = conn.prepareStatement(sql);
            rs = pst.executeQuery();
            while (rs.next()) {
               student student = new student();
                student.setNum(rs.getLong(1));
                student.setName(rs.getString(2));
                student.setMajor(rs.getString(3));
                student.setMaths(rs.getInt(4));
                student.setChinese(rs.getInt(5));
                student.setEnglish(rs.getInt(6));


                list.add(student);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }
}
